import QtQuick 2.6
import QtQuick.Window 2.2
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import an.qt.Message 1.0
ApplicationWindow {
    id: root
    property int  someValue: 200
    signal qmlSignal(string  qmlMsg)
    function myQmlFunction(msg)
    {
     console.log("Got message 1:",msg)
        return "some retrun value 1"
    }
    function myQmlFunction2(msg)
    {
     console.log("Got message 2:",msg)
        return "........some retrun value 2"
    }
    visible: true
    width: 500
    height: 300
    title: qsTr("Qml Cpp 交互")
    Text{
        anchors.centerIn: parent
        text:msg2.author   //获取C++属性author
        Component.onCompleted: msg2.author="Jonah"  //设置C++属性author
    }
    Button{
        id:m_button
        text:qsTr("信号按钮")
    }
    Button{
        id:m_button2
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 100
        text:qsTr("发送QML信号")
        onClicked: root.qmlSignal("Hello Signal from QML");   //发送QML信号到C++
    }
    Button{
        id:quitButton
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 0
        anchors.right: parent.right
        anchors.rightMargin: 100
       Text{
           anchors.centerIn:  parent
            text:qsTr("退出qt")
            objectName: "quitButtonText"
       }
        objectName: "quitButton"

    }
        Connections{
            target: m_button
            onClicked: {
                msg2.author="wocao"   //设置C++属性
                msg2.postMessage("打印")  //调用C++方法
                msg2.doSomeThing(Message.MESSAGE_COLOR_ALL)  //使用C++枚举类型
                msg2.refresh()  //调用C++槽
            }
        }
        Connections{    //连接C++信号到QML槽
            target: msg2
            onSendresfresh:{
                var v=sendvalue.toString("yyyy/MM/dd");
                console.log("C++ signal to Qml",v)
            }
        }
}
